]>
Commit | Line | Data |
---|---|---|
fdb4633d RBR |
1 | import SwiftUI |
2 | ||
3 | struct MapNotes: View { | |
4 | ||
5 | let mapSize: CGSize | |
6 | let lineWidth: CGFloat | |
7 | let notes: [Note] | |
e2c37ac1 | 8 | |
fdb4633d | 9 | let maxWidth = 400.0 |
fdb4633d RBR |
10 | |
11 | var body: some View { | |
12 | ForEach(notes, id: \.id) { note in | |
e2c37ac1 | 13 | Text(note.text.replacingOccurrences(of: "\\n", with: "\n")).font(.theme.note) |
fdb4633d RBR |
14 | .padding(2.0) |
15 | .background(.white) | |
16 | .foregroundColor(.map.labelColor) | |
17 | .border(Color.map.vertexColor, width: lineWidth) | |
18 | .frame(minWidth: 16.0, maxWidth: maxWidth, alignment: .topLeading) | |
19 | .offset( | |
20 | CGSize( | |
21 | width: w(note.position.x), | |
22 | height: h(note.position.y) | |
23 | ) | |
24 | ) | |
25 | } | |
26 | } | |
27 | ||
28 | func h(_ dimension: CGFloat) -> CGFloat { | |
29 | max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0)) | |
30 | } | |
31 | ||
32 | func w(_ dimension: CGFloat) -> CGFloat { | |
33 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
34 | } | |
35 | } | |
36 | ||
e2c37ac1 RBR |
37 | #Preview { |
38 | MapNotes( | |
39 | mapSize: CGSize(width: 400.0, height: 400.0), lineWidth: 1.0, | |
40 | notes: [ | |
41 | Note( | |
42 | id: 0, position: CGPoint(x: 50.0, y: 50.0), | |
43 | text: | |
44 | "Notes can have a lot more text, so we need to make sure that they're resized correctly") | |
45 | ]) | |
fdb4633d | 46 | } |